// 根据输入框的keyword发送请求，返回搜索结果

export const getSearchResults = async (keyword, proxy) => {

    // URL 编码关键词
    const encodedKeyword = encodeURIComponent(keyword);
    console.log(encodedKeyword);

    try {
        const response = await proxy.$http.get(`/api/book/search/${encodedKeyword}`);
        if (response.data) {
            const books = response.data.data.book;
            return books;
        } 
        else {
            console.error('Failed to search', response);
            return [];
        }
    } catch (error) {
        console.error('Error searching:', error);
        return [];
    }
};
